// Copyright (c)  YISH. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using NSQL.Generator;
using NSQL.Parser;
using NSQL.Sharpen;

namespace NSQL.Statements
{
    /// <summary>
    /// The UNION operator is used to combine the result-set of two or more SELECT statements.
    /// </summary>
    /// <remarks>
    /// <para>1. Each SELECT statement within UNION must have the same number of columns</para>
    /// <para>2. The columns must also have similar data types</para>
    /// <para>3. The columns in each SELECT statement must also be in the same order</para>
    /// </remarks>
    public class UnionStatement : IDataTableStatement
    {
        public IDataTableStatement Left { get; set; }
        public IDataTableStatement Right { get; set; }
        public UnionType Type { get; set; }
        public int Skip { get; set; }
        public int Limit { get; set; }
        public UnionStatement(IDataTableStatement left, IDataTableStatement right, UnionType type)
        {
            Left = left;
            Right = right;
            Type = type;
        }
        public string Accept(ISqlGenerator generator) => generator.Generate(this);
        public object Tag { get; set; }
        
        public Identifier Alias { get; set; }
        public JoinNode Join { get; set; }
        public bool IsDual => false;
        object IDeepClone.DeepCopy()
        {
            return new UnionStatement(Left, Right, Type)
            {
                Tag = Tag,
                Alias = Alias,
                Skip = Skip,
                Limit = Limit,
                Join = Join.DeepClone()
            };
        }
    }
}